#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

vector<vector<int>> threeSum(vector<int>& nums)
{
    vector<vector<int>> ret;
    int n = nums.size();
    sort(nums.begin(), nums.end());

    for (int i = 0; i < n; i++)
    {
        int left = i + 1;
        int right = n - 1;
        while (left < right)
        {
            int sum = nums[left] + nums[right] + nums[i];
            if (sum > 0)
            {
                right--;
            }
            else if (sum < 0)
            {
                left++;
            }
            else
            {
                ret.push_back({ nums[left] , nums[right] , nums[i] });
                left++;
                right--;
                while (left < right && nums[left] == nums[left - 1]) left++;
                while (left < right && nums[right] == nums[right + 1]) right--;
            }
        }
        while (i < n - 2 && nums[i] == nums[i + 1]) i++;
    }
    return ret;
}

int main()
{
    vector<int> v1 = { 0,0,0 };
    vector<vector<int>> v2 = threeSum(v1);
    for (int i = 0; i < v2.size(); i++)
    {
        for (int j = 0; j < v1.size(); j++)
        {
            cout << v2[i][j] << " ";
        }
    }

	return 0;
}